package com.serkol.ams;

import cn.hutool.core.date.DateUtil;
import com.serkol.ams.entity.OrderMaster;
import com.serkol.ams.entity.UsersAuthentication;
import com.serkol.utils.OrderUtils;
import net.xpyun.platform.opensdk.util.PrinterQuery;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.*;

public class Demo {
    public static void main(String[] args) {
//        OrderMaster goods=new OrderMaster();
//        Field[] fields = goods.getClass().getFields();
//        Field[] declaredFields = goods.getClass().getDeclaredFields();
//        StringBuilder sb=new StringBuilder();
//        for (int i = 0; i < declaredFields.length; i++) {
//            Field field = declaredFields[i];
//           // sb.append(field.getName().toUpperCase()+" as "+field.getName()+",");
//         //   System.out.println("sb.append(\""+field.getName().toUpperCase()+" as "+field.getName()+"\")");
//          //  Field next = iterator.next();
//          //  System.out.println(field.getName());
//            System.out.println(field.getName()+":0");
//        }
//       // System.out.println(sb.toString());

        //  System.out.println(OrderUtils.getSn());
        //  System.out.println(getOrderNum(1L));
        //2022092116481269651200001
        //2022092116484160250000001
        //   BigDecimal balance=new BigDecimal(30);
        // balance.multiply(BigDecimal.valueOf(10));

        //   System.out.println(balance);
//typeScriptRender();
        //  MD5 md5 = MD5.create();
        //   String s = md5.digestHex("123456");
        //e10adc3949ba59abbe56e057f20f883e
        //   System.out.println(s);
        //  sqlRender();
//        DateTime dateTime = DateUtil.offsetDay(new Date(), 30);
//        System.out.println(dateTime);
        //Date date = DateUtils.addDays(new Date(), -30);
        //  System.out.println(DateTime.of(date));
     /*   ResultCode[] values = ResultCode.values();
        for (int i = 0; i < values.length; i++) {
            ResultCode value = values[i];
            System.out.println(value.getMsg()+"="+value.getCode());
        }*/
        //  String file = Demo.class.getResource("/assets/img/invalid.jpg").getPath();
        //   System.out.println(file);
    //    int[] a = {1, 2};


        //   String join = Ints.join(",", a);
        //   System.out.println(join);
        //  OrderUtils.getInvalidCode(1);
        // String uuid = IdUtil.randomUUID();
        //   System.out.println(uuid);

/*        BigDecimal bigDecimal=null;
     bigDecimal = goPersent(new BigDecimal(1715.00), new BigDecimal(20.00));
       System.out.println("1715%20="+bigDecimal);

        bigDecimal = goPersent(new BigDecimal(9747), new BigDecimal(25.00));
        System.out.println("9747%25="+bigDecimal);

        bigDecimal = goPersent(new BigDecimal(90000.00), new BigDecimal(30.00));
        System.out.println("90000%30="+bigDecimal);*/

/*        OrderMaster orderMaster=new OrderMaster();
        orderMaster.setUserId(18L);
        orderMaster.setOperatorId(18L);
        orderMaster.setAddressId(15L);
        orderMaster.setSn(OrderUtils.getOrderNum(18L));
        orderMaster.setPaymentAmount(BigDecimal.valueOf(90240.00));
        orderMaster.setCreateDate(new Date());
        List<Map<String,Object>> orderDetails=new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Map<String,Object> map=new HashMap<>();
            map.put("name"," رەيھان ئۈستىقۇددۇس ئىچىملىكى ");
            map.put("price",BigDecimal.valueOf(598.00));
            map.put("count",i+1);
            orderDetails.add(map);

        }


         String prenter = getPrenter(orderMaster,orderDetails);
        System.out.println(prenter);*/
        formatName("test_name_text");

    }

    public static void formatName(String test) {
        //String test = "test_name_text";

        // 严格检查输入
        if (StringUtils.isEmpty(test) || test.trim().replaceAll("\\p{Z}", "").isEmpty()) {
            System.out.println("Invalid input");
            return;
        }

        // 分割字符串并去除空部分
        String[] parts = test.split("_", -1);
        parts = Arrays.stream(parts).filter(part -> !part.isEmpty()).toArray(String[]::new);

        if (parts.length < 1) {
            System.out.println("Input does not contain enough parts");
            return;
        }

        // 使用StringBuilder进行字符串拼接
        StringBuilder result = new StringBuilder();
        result.append(parts[0].toLowerCase());

        for (int i = 1; i < parts.length; i++) {
            if (parts[i].length() > 0) {
                result.append(Character.toUpperCase(parts[i].charAt(0)));
                if (parts[i].length() > 1) {
                    result.append(parts[i].substring(1).toLowerCase());
                }
            }
        }

        System.out.println(result.toString());
    }
    private static void typeScriptRender() {
        UsersAuthentication goods = new UsersAuthentication();
        Class<? extends UsersAuthentication> aClass = goods.getClass();
        Field[] fields = aClass.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            System.out.println(field.getName() + ":" + field.getType().getSimpleName().toLowerCase() + ";");
            //System.out.println(field.getType().getSimpleName());
        }
    }

    private static void sqlRender() {
        OrderMaster goods = new OrderMaster();
        Field[] fields = goods.getClass().getFields();
        Field[] declaredFields = goods.getClass().getDeclaredFields();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < declaredFields.length; i++) {
            Field field = declaredFields[i];
            //   sb.append(field.getName().toUpperCase()+" as "+field.getName()+",");
            System.out.println("sb.append(\"" + field.getName().toUpperCase() + " as " + field.getName() + "\");");
            //  Field next = iterator.next();
            //  System.out.println(field.getName());
            //    System.out.println(field.getName()+":0");
        }
        //   System.out.println(sb.toString());
    }

    private static BigDecimal goPersent(BigDecimal number, BigDecimal p) {

        final BigDecimal divide = p.divide(new BigDecimal(100));


        BigDecimal thirtyPercent = number.multiply(divide);

        return thirtyPercent;
    }


    public static   String  getPrenter(OrderMaster orderMaster, List<Map<String, Object>> orderDetails){
         String format = DateUtil.format(orderMaster.getCreateDate(), "yyyy-MM-dd HH:mm:ss");
        PrinterQuery printerQuery=new PrinterQuery();
        printerQuery.rtl();
        printerQuery.cb("圆规公司");
        printerQuery.br();
        printerQuery.addRow("نۇمۇرى:"+orderMaster.getSn());
        printerQuery.addRow("زاكاس ۋاقتى:"+format);
        printerQuery.line58();
        printerQuery.addGoodsHeader("نامى","سانى","باھاسى");
        printerQuery.line58();
         Iterator<Map<String, Object>> iterator = orderDetails.iterator();
        while (iterator.hasNext()) {
             Map<String, Object> next = iterator.next();
             int count =(int)next.getOrDefault("count", 0);
            BigDecimal price =(BigDecimal)next.getOrDefault("price", 0);
            printerQuery.addGoods((String) next.get("name"), count,price);

        }
      //  printerQuery.addGoods("Test",2,BigDecimal.valueOf(3.5));
      //  printerQuery.addGoods("Test1",3,BigDecimal.valueOf(4.5));
        printerQuery.line58();
        printerQuery.addRow("تۆلەنگەن پۇل:"+orderMaster.getPaymentAmount().doubleValue()+"￥");
        printerQuery.addRow(" چۈشۈرگۈچى:"+"艾山·库尔班");


        return printerQuery.build();
    }

}
